package com.taotao.wifepojie.test;

import java.math.BigInteger;

/**
 * @author wangjin
 * @title: Exponentiation
 * @projectName wife-pojie
 * @description: TODO
 * @date 2022/4/18 0018 17:37
 */
public class Exponentiation {
    public static void main(String[] args) {
        //X 小于 2的31次幂
        int X=7;
        BigInteger pow = BigInteger.valueOf(2).pow(31);
        BigInteger bigInteger = BigInteger.valueOf(Integer.valueOf(X));
           if(bigInteger.compareTo(pow)==-1){
               System.out.println(highestOneBit(X));
           }

    }
    public static int highestOneBit(int i) {

        // HD, Figure 3-1
        i |= (i >>  1);
        i |= (i >>  2);
        i |= (i >>  4);
        i |= (i >>  8);
        i |= (i >> 16);
        int j= i - (i >>> 1);
        return j*2;
    }
}
